package info.opensoaring.server;

import info.opensoaring.util.igc.optimize.Fai3TpOptimizer;
import info.opensoaring.util.igc.optimize.FlightOptimizer;
import info.opensoaring.util.igc.optimize.OutReturnOptimizer;

import java.util.ArrayList;
import java.util.logging.Logger;

import javax.jdo.JDOHelper;
import javax.jdo.PersistenceManagerFactory;

import org.dozer.DozerBeanMapper;
import org.dozer.Mapper;

import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import com.google.inject.Singleton;

public class OpenSoaringModule extends AbstractModule {

    public static Logger logger = Logger.getLogger(OpenSoaringModule.class.getName());

    @Override
    protected void configure() {

    }

    @Provides
    @Singleton
    public Mapper getBeanMapper() {
	ArrayList<String> mappings = new ArrayList<String>();
	mappings.add("jdoModelMapping.xml");
	return new DozerBeanMapper(mappings);
    }

    @Provides
    @Singleton
    public PersistenceManagerFactory getPersistenceManagerFactory() {
	return JDOHelper.getPersistenceManagerFactory("transactions-optional");
    }

    @Provides
    @Singleton
    public UserService getUserService() {
	return UserServiceFactory.getUserService();
    }

    @Provides
    @Singleton
    public FlightOptimizer[] getOptimizers() {
	return new FlightOptimizer[] { new Fai3TpOptimizer(), new OutReturnOptimizer() };
    }

}
